#include <iostream>
#include "i_include.cpp"

// number of iterations to perform of each test
int const NUM_OF_TESTS = 15;

int main(int argc, char** argv)
{
	int i, j, c, x, y, z;
	
	// setup trace log for unit testing
	TRACE_LEVEL = TRACE_LEVEL_INFO;
	trace(TRACE_LEVEL_INFO, "BEGAN unit testing.");
	
	// variance: give a commandline argument for a different
	// seed of the random number generator
	srand(argc > 1 ? atoi((C_STR)++argv) : 0);
	
	// ##### test 1: accurate evaluation of positional and material value
	trace(TRACE_LEVEL_INFO, "BEGAN Test 1.");
	I_CHESS_POSITION* board1 = start_board(); MOVELIST moves_ptr;
	
	for (i = 0; i < NUM_OF_TESTS; ++i)
	{
		// get the current player and legal moves
		z = gen_move_list(board1, moves_ptr);
		c = board1->col;
		
		for (j = 0; j < z; ++j)
		{
			// retrieve the "modified" pos/mat values
			x = moves_ptr[j]->board[MOVE_TO]->pos[c];
			y = moves_ptr[j]->board[MOVE_TO]->mat[c];
			
			// compute the pos/mat values naively
			eval_material_value(moves_ptr[j]->board[MOVE_TO]);
			
			// assert that these two values are identical
			trace_assert(x == moves_ptr[j]->board[MOVE_TO]->pos[c], "FAILED to match positional values.");
			trace_assert(y == moves_ptr[j]->board[MOVE_TO]->mat[c], "FAILED to match material values.");
		};
		
		// apply a random move, and continue
		apply_move(board1, moves_ptr[rand() % j]);
	};
	
	// test 1: print success message
	trace(TRACE_LEVEL_INFO, "SUCCESSFULLY completed Test 1.");
	
	// ##### test 2: get some "random" values from mt_rand32();
	trace(TRACE_LEVEL_INFO, "BEGAN Test 2.");
	
	// setup mersenne twister and generate many random numbers
	mt_setup(rand()); for (i = 0; i < 1000; ++i) mt_rand32();
	
	// test 2: print success message
	trace(TRACE_LEVEL_INFO, "SUCCESSFULLY completed Test 2.");
};
